package main;

import java.awt.AWTException;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.MenuItem;
import java.awt.Point;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.event.MouseMotionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowStateListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Vector;

import javax.imageio.ImageIO;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DropMode;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.SwingUtilities;
import javax.swing.JPopupMenu.Separator;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreeCellRenderer;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;

import kr.db.EmployeeSearchDTO;
import voSetting.EmployeeSearchVO;
import voSetting.PortVO;
import voSetting.StateSetVO;
import chat.Chatting;
import chat.Note;
import custom.tree.CustomTreeNode;
import custom.tree.EmployeesSearch;
import file.FileTransfer;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.border.TitledBorder;
import javax.swing.ImageIcon;
import java.awt.FlowLayout;
import javax.swing.border.EtchedBorder;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
import javax.swing.UIManager;
import javax.swing.JLayeredPane;
import javax.swing.border.LineBorder;

public class Main extends JFrame {
	Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
	int width= (int)screenSize.getWidth();
	int height = (int)screenSize.getHeight();

	Point point = new Point();  
	boolean resizing = false; 
	boolean maximum = false;
	
	ClientThread clientThread;
	Note note_f;
	Chatting chat_f;
	FileTransfer file_f;
	EmployeesSearch em_f;
	Login login_f = new Login();
	
	CustomTreeNode dm_root;
    CustomTreeNode dm_group;
    CustomTreeNode dm_team;
    CustomTreeNode dm_name;
    
    CustomTreeNode selectedNode;
	Object obj;
	String m_id;
	String e_name;
    
	Vector<String> v_selected = new Vector<String>(); // 전부 하나로 합침 Employees chatting grouplist (to)
	Vector<String> v_selected_chat	 = new Vector<String>();				

	String [] statement = {"업 무 중", "자리비움", "외 출 중", "회 의 중", "식 사 중"};
	boolean DEBUG = true;

	File list_save = new File("list_data.dat");
	public ArrayList<EmployeeSearchVO> save = new ArrayList<EmployeeSearchVO>();
	public String group_name;
	public String team_name;
	public EmployeeSearchVO  add_user_name = new EmployeeSearchVO();
	
	static TreeCellRenderer renderer = null;
	TrayIcon trayIcon;
	SystemTray tray;
	
	private JPanel contentPane;
	private JPanel panel_center;
	private JMenuBar menuBar;
	private JMenu menu_my;
	private JMenu menu_work;
	private JMenu menu_message;
	private JMenu menu_help;
	private JMenuItem mntmNewMenuItem;
	private JMenuItem menuItem_attendence;
	private JMenuItem menuItem_close;
	private JMenuItem menuItem_notice;
	private JMenuItem menuItem_workfile;
	private JMenuItem menuItem_schedule;
	private JMenuItem menuItem_12;
	private JMenuItem menuItem_14;
	private JMenuItem menuItem_16;
	private JMenuItem menuItem_info;
	private JMenuItem menuItem;
	private JMenuItem menuItem_22;
	private JSeparator separator;
	private JSeparator separator_1;
	private JPanel panel_myinfo;
	private JPanel panel_employees;
	private JPanel panel_myinfo_north;
	private JPanel panel_myinfo_menu;
	private JPanel panel_employees_search;
	private JLabel lblNewLabel_1;
	private JTextField textField_1;
	private JButton btnNewButton;
	private JScrollPane scrollPane_1;
	private JButton btnNewButton_1;
	private JButton btnNewButton_3;
	private JLabel lbl_name;
	private JButton btnNewButton_4;
	private JComboBox comboBox;
	private JMenuItem menuItem_environment;
	private JPanel panel_myinfo_center;
	private JLabel lbl_position;
	private JTree tree;
	private JLabel lbl_team;
	private JPanel panel_icon_menu;
	private JButton btn_minimize;
	private JButton btn_maximize;
	private JButton btn_close;
	private JPanel panel_myinfo_name;
	private JPanel panel_south;
	private JTextField txt_notice;
	private JTextField txt_team;
	private JMenuItem menuItem_myinfo;
	private JSeparator separator_2;
	private JPanel panel;
	private JPanel panel_2;
	private JButton button;
	private JPanel panel_1;
	private JPanel panel_3;
	private JLayeredPane layeredPane;
	private JLabel lblNewLabel_2;
	private JLabel lblNewLabel;


	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Main frame = new Main();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Main() {
		setUndecorated(true);
		
		int taskbarheight = (int) (Toolkit.getDefaultToolkit().getScreenSize().height 
			    - GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().getHeight());
		setBackground(Color.WHITE);
		//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setDefaultCloseOperation(JFrame.ICONIFIED);
		setBounds(width-300, 0, 300, 500);
		setMinimumSize(new Dimension(300, 500));
		contentPane = new JPanel();
		contentPane.setBackground(new Color(152,191,218));
		contentPane.setBorder(new LineBorder(Color.DARK_GRAY));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		contentPane.add(getLayeredPane_1(), BorderLayout.CENTER);
		contentPane.add(getPanel_center(), BorderLayout.CENTER);
		contentPane.add(getPanel_17(), BorderLayout.SOUTH);
		loadMyGroup();
		addWindowListener(new WindowAdapter() {			
			@Override
			public void windowClosing(WindowEvent e) {
				systemIcon();
			    setExtendedState(JFrame.ICONIFIED); 
/*				if(clientThread == null){
				}
				else{
					StateSetVO ssvo = new StateSetVO();
					ssvo.setVo_type(4);
					ssvo.setVo(clientThread.getSmvo());
					clientThread.typeChange(null,"");
					try {
						clientThread.oos.writeObject(ssvo);
						clientThread.oos.flush();
					} catch (IOException e1) {
						e1.printStackTrace();
					}
				
				}*/
			}
		});
		addMouseListener(new MouseAdapter() {  
		      public void mousePressed(MouseEvent e) {  
		        resizing = getCursor().equals(Cursor.getDefaultCursor())? false:true;  
		        if(!e.isMetaDown()){  
		          point.x = e.getX();  
		          point.y = e.getY();  
		        }  
		      }  
		    });  
		addMouseMotionListener(new MouseMotionAdapter() {  
		      public void mouseDragged(MouseEvent e) {  
		        if(resizing){  
		          Point pt = e.getPoint(); 
		          setSize(getWidth()+pt.x - point.x, getHeight()+pt.y-point.y);  
		          point.x = pt.x;  
		          point.y = pt.y;
		        }  
		        else if(!e.isMetaDown()){  
		        Point p = getLocation();  
		        setLocation(p.x + e.getX() - point.x,  
		            p.y + e.getY() - point.y);  
		        }  
		      }  
		      public void mouseMoved(MouseEvent me){  
		        Point cursorLocation = me.getPoint();  
		        int xPos = cursorLocation.x;  
		        int yPos = cursorLocation.y;  
		        if(xPos < 5) setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));  
		        else if(xPos > getContentPane().getWidth()-5) setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));  
		        else if(yPos < 5) setCursor(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR));  
		        else if(yPos > getContentPane().getHeight()-5) setCursor(Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR));  
		        else if(getCursor().equals(Cursor.getDefaultCursor()) == false) setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));  
		      }  
		    });
		
	}

	public void setInfo(ClientThread clientThread) {
		this.clientThread = clientThread;
	}
	// Set TrayIcon
	private void systemIcon(){
	    if (!SystemTray.isSupported()) {
	        System.out.println("SystemTray가 지원되지 않습니다.");
	        return;
	    }	    
	    SystemTray tray = SystemTray.getSystemTray();
	    Toolkit toolkit = Toolkit.getDefaultToolkit();
	    Image image = Toolkit.getDefaultToolkit().getImage("C:\\Program Files\\Mino Corp\\icon\\trayicon.png");

	    PopupMenu iconmenu = new PopupMenu();
	    MenuItem openItem = new MenuItem("Open");
	    MenuItem noteItem = new MenuItem("Note");
	    MenuItem fileItem = new MenuItem("File");
	    MenuItem chattingItem = new MenuItem("Chatting");
	    MenuItem closeItem = new MenuItem("Close");
	    MenuItem logoutItem = new MenuItem("Logout");
	    iconmenu.add(openItem);
	    iconmenu.add(noteItem);
	    iconmenu.add(fileItem);
	    //iconmenu.add(logoutItem);
	    iconmenu.add(closeItem);
	        

	     TrayIcon icon = new TrayIcon(image, "Mino Messanger : "+ e_name, iconmenu);
	     icon.setImageAutoSize(true);
	     icon.addMouseListener(new MouseAdapter() {
	    	 @Override
				public void mouseClicked(MouseEvent e) {
					if (e.getClickCount() == 2) { // double-clicked
						tray.remove(icon);
			    		setVisible(true);
					} else if (e.getClickCount() == 3) { // triple-clicked
						tray.remove(icon);
			    		 setVisible(true);
			    		toFront();
					}
				}
	     });
	     
	     try {
			tray.add(icon);
		} catch (AWTException e1) {
			e1.printStackTrace();
		}	     
	     openItem.addActionListener(new ActionListener() {
	    	 public void actionPerformed(ActionEvent e) {
	    		 tray.remove(icon);
	    		 setVisible(true);
	    		 toFront();
	    		 setFocusable(true);
	    		 setFocusableWindowState(true);
	    	 }
	     });	     
	     noteItem.addActionListener(new ActionListener() {
	    	 public void actionPerformed(ActionEvent e) {
	    		 noteWrite();
	    	 }
	     });	     
	     fileItem.addActionListener(new ActionListener() {
	    	 public void actionPerformed(ActionEvent e) {
	    		 fileTrans();
	    	 }
	     });	     
	     logoutItem.addActionListener(new ActionListener() {
	    	 public void actionPerformed(ActionEvent e) {
	    		 tray.remove(icon);
	    		 login_f.setVisible(true);
	    		 dispose();
	    	 }
	     });
	     closeItem.addActionListener(new ActionListener() {
	    	 public void actionPerformed(ActionEvent e) {
	    		 if(clientThread == null){
					}
					else{
						StateSetVO ssvo = new StateSetVO();
						ssvo.setVo_type(4);
						ssvo.setVo(clientThread.getSmvo());
						clientThread.typeChange(null,"");
						try {
							clientThread.oos.writeObject(ssvo);
							clientThread.oos.flush();
						} catch (IOException e1) {
							e1.printStackTrace();
						}
					
					}
	    		 SaveMyGroup();
	    		 tray.remove(icon);
	    		 dispose();
	    	 }
	     });
	}
	
	
	public void SaveMyGroup() {
		if(list_save.delete()){
			System.out.println("기존 파일 삭제 성공");
		}
		
		show_save_file_info(save);
		try {
			ObjectOutputStream oos = new ObjectOutputStream(
					new FileOutputStream(list_save));
			oos.writeObject(save);
			oos.close();
		} catch (IOException err) {
			err.printStackTrace();
		}
	}
	
	public void show_save_file_info(ArrayList<EmployeeSearchVO> al){
		System.out.println("저장된 리스트 사이즈 : " + al.size());
		EmployeeSearchVO v;
		for(int i = 0; i < al.size(); i++){
			v = al.get(i);
			System.out.println("==== 직원 정보 ====");
			System.out.println("이름 : " + v.getEmployee_name());
			System.out.println("직위 : " + v.getEmployee_position());
			System.out.println("기존 그룹 : " + v.getGroup());
			System.out.println("기존 팀 : " + v.getTeam());
			System.out.println("변경된 그룹 : " + v.getCp_group());
			System.out.println("변경된 팀 : " + v.getCp_team());
			System.out.println("아이디 : " + v.getM_id());
			System.out.println("==== ====== ====");
		}
	}
	/* Load My Group */
	public void loadMyGroup() {
		EmployeeSearchDTO esDto = new EmployeeSearchDTO();
		EmployeeSearchVO esvo = new EmployeeSearchVO();
		
		ArrayList<EmployeeSearchVO> al = null;
		
		if (list_save.exists()) {
			System.out.println("트루");
			try {
				 ObjectInputStream ois = new ObjectInputStream(new FileInputStream(list_save));
				 al = (ArrayList<EmployeeSearchVO>) ois.readObject();
				ois.close();
			} catch (IOException err) {
				err.printStackTrace();
			} catch (ClassNotFoundException err) {
				err.printStackTrace();
			}
		}
		else{
			System.out.println("엘스");
			al = esDto.select(esvo);
			
			SaveMyGroup();
		}
		save = al;
		show_save_file_info(al);//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
		if (true) {
			
			EmployeeSearchVO evo =  new EmployeeSearchVO();
		      evo.setGroup("전체 직원");
		      evo.setTeam("전체 팀");
		      
		      dm_root = new CustomTreeNode("전체 직원", evo);
		      
		      for (int i = 0; i < al.size(); i++) {
		         int group_num = -1;
		         int team_num = -1;

		         EmployeeSearchVO v = al.get(i);
		         
		         if (dm_root.getChildCount() >= 1) { // 루트 이하에 값이 있다면
		            for (int group_count = 0; group_count < dm_root.getChildCount(); group_count++) {

		               if (v.getCp_group().equals(
		                     dm_root.getChildAt(group_count).toString())) {
		                  group_num = group_count;
		                  for (int team_count = 0; team_count < dm_root
		                        .getChildAt(group_count).getChildCount(); team_count++) {
		                     if (v.getCp_team().equals(
		                           dm_root.getChildAt(group_count)
		                                 .getChildAt(team_count).toString())) {
		                        team_num = team_count;
		                        break;
		                     }// end if -team
		                  }// end for -team
		                  break;
		               }// end if - group
		            }// end for - group
		         }
		         
		         if (group_num == -1) { // 새 그룹을 생성
		            dm_group = new CustomTreeNode(v.getCp_group()); // 루트에 값을
		                                                      // 생성
		            dm_team = new CustomTreeNode(v.getCp_team());
		            dm_root.add(dm_group);
		            dm_group.add(dm_team);
		            dm_name = new CustomTreeNode(v.getEmployee_name(),v);
		            dm_team.add(dm_name);

		         }
		         else { // 기존 그룹에 추가
		            if (team_num == -1) { // 기존 그룹의 새 팀을 추가
		               dm_group = (CustomTreeNode) dm_root.getChildAt(group_num);
		               dm_team = new CustomTreeNode(v.getCp_team());
		               dm_name = new CustomTreeNode(v.getEmployee_name(),v);
		               dm_team.add(dm_name);
		               dm_group.add(dm_team);
		            } else {
		               dm_group = (CustomTreeNode) dm_root.getChildAt(group_num);
		               dm_team = (CustomTreeNode) dm_root.getChildAt(
		                     group_num).getChildAt(team_num);

		               dm_name = new CustomTreeNode(v.getEmployee_name(),v);
		               dm_team.add(dm_name);
		            }
		         }
		      }// end for
		      this.scrollPane_1.setViewportView(setTree_1(dm_root));
		}
		
	}

	public JTree setTree_1(CustomTreeNode dm_group) {
	      tree = new JTree(dm_group);
	      tree.setBorder(new EmptyBorder(5, 5, 5, 5));
	      tree.setBackground(new Color(255, 255, 255));
	      
			tree.setEditable(true);
			tree.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
			tree.setDragEnabled(true);
			tree.setDropMode(DropMode.ON_OR_INSERT);
			/*
			 * tree.setTransferHandler(new TransferHandler()); // 클래스를 만들거나 드래그
			 * 했을 때, 들어가는 방법
			 */
			tree.getSelectionModel().setSelectionMode(
					TreeSelectionModel.CONTIGUOUS_TREE_SELECTION);
			// expandTree(tree);
			
			renderer = new ToolTipTreeCellRenderer(tree);
	        tree.setCellRenderer(renderer);
	         
			tree.addMouseListener(new MouseAdapter() { // 트리를 눌렀을 때
				public void mousePressed(MouseEvent event) {
					/*
					 * if (DEBUG && tree.getSelectionCount() > 0) {
					 * CustomTreeNode selectedNode = getSelectedNode();
					 * Object obj = selectedNode.getUserObject(); Object pobj =
					 * null; CustomTreeNode parentNode =
					 * (CustomTreeNode) selectedNode .getParent(); if
					 * (parentNode != null) pobj = parentNode.getUserObject();
					 * 
					 * System.out.println("선택: [" + obj + "], 최하위여부[" +
					 * selectedNode.isLeaf() + "], 상위:[" + pobj + "]");
					 * 
					 * }
					 */
					if (SwingUtilities.isRightMouseButton(event)) {
						int row = tree.getClosestRowForLocation(event.getX(),
								event.getY());
						tree.setSelectionRow(row);
					}
					if (((event.getModifiers() & InputEvent.BUTTON3_MASK) != 0)
							&& (tree.getSelectionCount() > 0)) {
						showMenu(event.getX(), event.getY());
					}

				}

				@Override
				public void mouseClicked(MouseEvent e) {
					if (e.getClickCount() == 2) { // double-clicked
						chat_set();
					} else if (e.getClickCount() == 3) { // triple-clicked
						chat_set();
					}
				}
			});
	      return tree;
	   }
	
	/* Save My Group */
/*	public void SaveMyGroup() {
	try {
		ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(serFile));
			oos.writeObject(dm_root);
			oos.close();
		} catch (IOException err) {
			err.printStackTrace();
		}	
	}
*/
	private JPanel getPanel_center() {
		if (panel_center == null) {
			panel_center = new JPanel();
			panel_center.setBorder(null);
			panel_center.setLayout(new BorderLayout(0, 0));
			panel_center.add(getPanel_myinfo(), BorderLayout.NORTH);
			panel_center.add(getPanel_employees(), BorderLayout.CENTER);
		}
		return panel_center;
	}

	private JMenuBar getMenuBar_1() {
		if (menuBar == null) {
			menuBar = new JMenuBar();
			menuBar.setOpaque(false);
			menuBar.setBorder(null);
			menuBar.add(getMenu_my());
			menuBar.add(getMenu_work());
			menuBar.add(getMenu_message());
			menuBar.add(getMenu_help());
		}
		return menuBar;
	}

	private JMenu getMenu_my() {
		if (menu_my == null) {
			menu_my = new JMenu("");
			menu_my.setIcon(new ImageIcon("C:\\Program Files\\Mino Corp\\image\\mini_logo.png"));
			menu_my.setIconTextGap(0);
			menu_my.setAlignmentX(0.0f);
			menu_my.setFont(new Font("맑은 고딕", Font.BOLD, 12));
			menu_my.add(getMenuItem_myinfo());
			menu_my.add(getSeparator_2_1());
			menu_my.add(getMenuItem_attendence());
			menu_my.add(getMenuItem_environment());
			menu_my.add(getSeparator());
			//mnNewMenu.add(getMntmNewMenuItem());
			menu_my.add(getMenuItem_close());
		}
		return menu_my;
	}

	private JMenu getMenu_work() {
		if (menu_work == null) {
			menu_work = new JMenu("업무사항");
			menu_work.setForeground(Color.DARK_GRAY);
			menu_work.setIconTextGap(0);
			menu_work.setAlignmentX(0.0f);
			menu_work.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
			menu_work.add(getMenuItem_notice());
			menu_work.add(getSeparator_1());
			menu_work.add(getMenuItem_schedule());
			menu_work.add(getMenuItem_workfile());
		}
		return menu_work;
	}

	private JMenu getMenu_message() {
		if (menu_message == null) {
			menu_message = new JMenu("메시지함");
			menu_message.setForeground(Color.DARK_GRAY);
			menu_message.setIconTextGap(0);
			menu_message.setAlignmentX(0.0f);
			menu_message.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
			menu_message.add(getMenuItem_12());
			menu_message.add(getMenuItem_14());
			menu_message.add(getMenuItem_16());
		}
		return menu_message;
	}

	private JMenu getMenu_help() {
		if (menu_help == null) {
			menu_help = new JMenu("Help");
			menu_help.setForeground(Color.DARK_GRAY);
			menu_help.setIconTextGap(0);
			menu_help.setAlignmentX(0.0f);
			menu_help.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
				}
			});
			menu_help.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
			menu_help.add(getMenuItem_info());
			menu_help.add(getMenuItem());
			menu_help.add(getMenuItem_22());
		}
		return menu_help;
	}

	private JMenuItem getMntmNewMenuItem() {
		if (mntmNewMenuItem == null) {
			mntmNewMenuItem = new JMenuItem("로그아웃");
			mntmNewMenuItem.setEnabled(false);
			mntmNewMenuItem.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					
				}
			});
			mntmNewMenuItem.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		}
		return mntmNewMenuItem;
	}

	private JMenuItem getMenuItem_attendence() {
		if (menuItem_attendence == null) {
			menuItem_attendence = new JMenuItem("근태확인");
			menuItem_attendence.setBackground(new Color(255, 255, 255));
			menuItem_attendence.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
				}
			});
			menuItem_attendence.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		}
		return menuItem_attendence;
	}

	private JMenuItem getMenuItem_close() {
		if (menuItem_close == null) {
			menuItem_close = new JMenuItem("메신저 종료");
			menuItem_close.setBackground(new Color(255, 255, 255));
			menuItem_close.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					if(clientThread == null){
						System.exit(1);
					}
					else{
						StateSetVO ssvo = new StateSetVO();
						ssvo.setVo_type(4);
						ssvo.setVo(clientThread.getSmvo());
						clientThread.typeChange(null,"");
						try {
							clientThread.oos.writeObject(ssvo);
							clientThread.oos.flush();
						} catch (IOException e1) {
							e1.printStackTrace();
						}
						System.exit(1);
					}
				}
			});
			menuItem_close.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		}
		return menuItem_close;
	}

	private JMenuItem getMenuItem_notice() {
		if (menuItem_notice == null) {
			menuItem_notice = new JMenuItem("공지사항");
			menuItem_notice.setBackground(new Color(255, 255, 255));
			menuItem_notice.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
				}
			});
			menuItem_notice.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		}
		return menuItem_notice;
	}

	private JMenuItem getMenuItem_workfile() {
		if (menuItem_workfile == null) {
			menuItem_workfile = new JMenuItem("업무양식");
			menuItem_workfile.setBackground(new Color(255, 255, 255));
			menuItem_workfile.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
				}
			});
			menuItem_workfile.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		}
		return menuItem_workfile;
	}

	private JMenuItem getMenuItem_schedule() {
		if (menuItem_schedule == null) {
			menuItem_schedule = new JMenuItem("스케쥴러");
			menuItem_schedule.setBackground(new Color(255, 255, 255));
			menuItem_schedule.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
				}
			});
			menuItem_schedule.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		}
		return menuItem_schedule;
	}

	private JMenuItem getMenuItem_12() {
		if (menuItem_12 == null) {
			menuItem_12 = new JMenuItem("메일함");
			menuItem_12.setBackground(new Color(255, 255, 255));
			menuItem_12.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
				}
			});
			menuItem_12.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		}
		return menuItem_12;
	}

	private JMenuItem getMenuItem_14() {
		if (menuItem_14 == null) {
			menuItem_14 = new JMenuItem("쪽지함");
			menuItem_14.setBackground(new Color(255, 255, 255));
			menuItem_14.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
				}
			});
			menuItem_14.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		}
		return menuItem_14;
	}

	private JMenuItem getMenuItem_16() {
		if (menuItem_16 == null) {
			menuItem_16 = new JMenuItem("파일함");
			menuItem_16.setBackground(new Color(255, 255, 255));
			menuItem_16.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
				}
			});
			menuItem_16.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		}
		return menuItem_16;
	}

	private JMenuItem getMenuItem_info() {
		if (menuItem_info == null) {
			menuItem_info = new JMenuItem("about MINO");
			menuItem_info.setBackground(new Color(255, 255, 255));
			menuItem_info.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		}
		return menuItem_info;
	}

	private JMenuItem getMenuItem() {
		if (menuItem == null) {
			menuItem = new JMenuItem("FAQ");
			menuItem.setBackground(new Color(255, 255, 255));
			menuItem.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
				}
			});
			menuItem.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		}
		return menuItem;
	}

	private JMenuItem getMenuItem_22() {
		if (menuItem_22 == null) {
			menuItem_22 = new JMenuItem("1 : 1 문의");
			menuItem_22.setBackground(new Color(255, 255, 255));
			menuItem_22.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
				}
			});
			menuItem_22.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		}
		return menuItem_22;
	}

	private JSeparator getSeparator() {
		if (separator == null) {
			separator = new JSeparator();
			separator.setBackground(new Color(255, 255, 255));
		}
		return separator;
	}

	private JSeparator getSeparator_1() {
		if (separator_1 == null) {
			separator_1 = new JSeparator();
			separator_1.setBackground(new Color(255, 255, 255));
		}
		return separator_1;
	}

	private JPanel getPanel_myinfo() {
		if (panel_myinfo == null) {
			panel_myinfo = new JPanel();
			panel_myinfo.setBackground(new Color(152,191,218));
			panel_myinfo.setLayout(new BorderLayout(0, 0));
			panel_myinfo.add(getPanel_myinfo_north(), BorderLayout.NORTH);
			panel_myinfo.add(getPanel_myinfo_menu(), BorderLayout.SOUTH);
			panel_myinfo.add(getPanel_myinfo_center(), BorderLayout.CENTER);
		}
		return panel_myinfo;
	}

	private JPanel getPanel_employees() {
		if (panel_employees == null) {
			panel_employees = new JPanel();
			panel_employees.setLayout(new BorderLayout(0, 0));
			panel_employees.add(getPanel_employees_search(), BorderLayout.SOUTH);
			panel_employees.add(getScrollPane_1(), BorderLayout.CENTER);
		}
		return panel_employees;
	}

	private JPanel getPanel_myinfo_north() {
		if (panel_myinfo_north == null) {
			panel_myinfo_north = new JPanel();
			panel_myinfo_north.setForeground(Color.DARK_GRAY);
			panel_myinfo_north.setBorder(null);
			panel_myinfo_north.setOpaque(false);
			panel_myinfo_north.setLayout(new BorderLayout(0, 0));
			panel_myinfo_north.add(getMenuBar_1(), BorderLayout.WEST);
			panel_myinfo_north.add(getPanel_icon_menu(), BorderLayout.EAST);
		}
		return panel_myinfo_north;
	}

	private JPanel getPanel_myinfo_menu() {
		if (panel_myinfo_menu == null) {
			panel_myinfo_menu = new JPanel();
			panel_myinfo_menu.setBorder(new EmptyBorder(3, 3, 3, 3));
			panel_myinfo_menu.setBackground(new Color(197,197,197));
			panel_myinfo_menu.setLayout(new BorderLayout(0, 0));
			panel_myinfo_menu.add(getPanel_2(), BorderLayout.EAST);
			panel_myinfo_menu.add(getButton(), BorderLayout.WEST);
		}
		return panel_myinfo_menu;
	}

	private JPanel getPanel_employees_search() {
		if (panel_employees_search == null) {
			panel_employees_search = new JPanel();
			panel_employees_search.setBackground(new Color(152,191,218));
			panel_employees_search.add(getLblNewLabel_1());
			panel_employees_search.add(getTextField_1());
			panel_employees_search.add(getBtnNewButton());
		}
		return panel_employees_search;
	}

	private JLabel getLblNewLabel_1() {
		if (lblNewLabel_1 == null) {
			lblNewLabel_1 = new JLabel("직원 검색");
			lblNewLabel_1.setForeground(Color.DARK_GRAY);
			lblNewLabel_1.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		}
		return lblNewLabel_1;
	}

	private JTextField getTextField_1() {
		if (textField_1 == null) {
			textField_1 = new JTextField();
			textField_1.addKeyListener(new KeyAdapter() {
				@Override
				public void keyReleased(KeyEvent e) {
					if(e.getKeyCode() == KeyEvent.VK_ENTER){
						btnNewButton.doClick();
					}
				}
			});
			textField_1.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
			textField_1.setColumns(13);
		}
		return textField_1;
	}

	private JButton getBtnNewButton() {
		if (btnNewButton == null) {
			btnNewButton = new JButton("검 색");
			btnNewButton.setForeground(Color.DARK_GRAY);
			btnNewButton.setBackground(new Color(152,191,218));
			btnNewButton.setBorder(null);
			btnNewButton.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) { // 문제있음. 오른쪽 버튼이 안나옴. 
						em_f = new EmployeesSearch();
						em_f.addEmployeeFrame(4, Main.this);
						em_f.setVisible(true);						
						em_f.setTxt_search(textField_1.getText());
						em_f.btn_search.doClick();
						textField_1.setText("");
				}
			});
			btnNewButton.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		}
		return btnNewButton;
	}

	private JScrollPane getScrollPane_1() {
		if (scrollPane_1 == null) {
			scrollPane_1 = new JScrollPane();
			scrollPane_1.setBorder(null);
			scrollPane_1.setViewportView(getTree());
		}
		return scrollPane_1;
	}
	//====================================================================

	private JButton getBtnNewButton_1() {
		if (btnNewButton_1 == null) {
			btnNewButton_1 = new JButton("");
			btnNewButton_1.setIcon(new ImageIcon("C:\\Program Files\\Mino Corp\\icon\\mail.png"));
			btnNewButton_1.setBackground(new Color(197,197,197));
			btnNewButton_1.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
				}
			});
			btnNewButton_1.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
			btnNewButton_1.setBorder(null);
		}
		return btnNewButton_1;
	}

	private JButton getBtnNewButton_3() {
		if (btnNewButton_3 == null) {
			btnNewButton_3 = new JButton("");
			btnNewButton_3.setIcon(new ImageIcon("C:\\Program Files\\Mino Corp\\icon\\file.png"));
			btnNewButton_3.setBackground(new Color(197,197,197));
			btnNewButton_3.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
				}
			});
			btnNewButton_3.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
			btnNewButton_3.setBorder(null);
		}
		return btnNewButton_3;
	}

	private JLabel getLbl_name() {
		if (lbl_name == null) {
			lbl_name = new JLabel("공소영");
			lbl_name.setBackground(new Color(152,191,218));
			lbl_name.setFont(new Font("맑은 고딕", Font.BOLD, 15));
		}
		return lbl_name;
	}
	
	private JLabel getLbl_team() {
		if (lbl_team == null) {
			lbl_team = new JLabel("기술지원부");
			lbl_team.setHorizontalAlignment(SwingConstants.TRAILING);
			lbl_team.setVerticalTextPosition(SwingConstants.BOTTOM);
			lbl_team.setBackground(new Color(152,191,218));
			lbl_team.setFont(new Font("맑은 고딕", Font.PLAIN, 11));
		}
		return lbl_team;
	}

	private JButton getBtnNewButton_4() {
		if (btnNewButton_4 == null) {
			btnNewButton_4 = new JButton("");
			btnNewButton_4.setIcon(new ImageIcon("C:\\Program Files\\Mino Corp\\icon\\message.png"));
			btnNewButton_4.setBackground(new Color(197,197,197));
			btnNewButton_4.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
				}
			});
			btnNewButton_4.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
			btnNewButton_4.setBorder(null);
		}
		return btnNewButton_4;
	}

	private JComboBox getComboBox() {
		if (comboBox == null) {
			comboBox = new JComboBox(statement);
			comboBox.setBackground(new Color(230, 230, 250));
			comboBox.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					state_change();
				}
			});
			comboBox.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		}
		return comboBox;
	}

	public void state_change(){
		int select_num = comboBox.getSelectedIndex();
		switch(select_num){
		case 0:
			break;
		case 1:
			break;
		case 2:
			break;
		case 3:
			break;
		case 4:
			break;
		}

	}
	private JMenuItem getMenuItem_environment() {
		if (menuItem_environment == null) {
			menuItem_environment = new JMenuItem("환경설정");
			menuItem_environment.setBackground(new Color(255, 255, 255));
			menuItem_environment.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
				}
			});
			menuItem_environment.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		}
		return menuItem_environment;
	}

	private JPanel getPanel_myinfo_center() {
		if (panel_myinfo_center == null) {
			panel_myinfo_center = new JPanel();
			panel_myinfo_center.setBorder(new EmptyBorder(0, 0, 3, 0));
			panel_myinfo_center.setBackground(new Color(152,191,218));
			panel_myinfo_center.setLayout(new BorderLayout(0, 0));
			panel_myinfo_center.add(getPanel_myinfo_name(), BorderLayout.WEST);
			panel_myinfo_center.add(getPanel(), BorderLayout.EAST);
			panel_myinfo_center.add(getPanel_1(), BorderLayout.CENTER);
		}
		return panel_myinfo_center;
	}

	private JLabel getLbl_position() {
		if (lbl_position == null) {
			lbl_position = new JLabel("사원");
			lbl_position.setBackground(new Color(152,191,218));
			lbl_position.setFont(new Font("맑은 고딕", Font.BOLD, 15));
		}
		return lbl_position;
	}

	private JTree getTree() {
		if (tree == null) {
		}
		return tree;
	}

	protected void showMenu(int x, int y) {
		CustomTreeNode select = getSelectedNode();
		JPopupMenu popupMenu = new JPopupMenu("메뉴");
		JMenuItem menuItem1 = new JMenuItem("쪽지쓰기");
		JMenuItem menuItem2 = new JMenuItem("채팅하기");
		JMenuItem menuItem3 = new JMenuItem("파일전송");
		JMenuItem menuItem4 = new JMenuItem("메일쓰기");
		JMenuItem menuItem5 = new JMenuItem("그룹명변경");
		JMenuItem menuItem6 = new JMenuItem("직원추가");
		JMenuItem menuItem7 = new JMenuItem("직원삭제");
		menuItem1.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		menuItem2.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		menuItem3.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		menuItem4.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		menuItem5.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		menuItem6.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		menuItem7.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		menuItem1.setBackground(Color.WHITE);
		menuItem2.setBackground(Color.WHITE);
		menuItem3.setBackground(Color.WHITE);
		menuItem4.setBackground(Color.WHITE);
		menuItem5.setBackground(Color.WHITE);
		menuItem6.setBackground(Color.WHITE);
		menuItem7.setBackground(Color.WHITE);
		if (select.isLeaf()) {
			popupMenu.add(menuItem1); //
			popupMenu.add(menuItem2);
			popupMenu.add(menuItem3);
			popupMenu.add(menuItem4);
			popupMenu.add(getSeparator());
			popupMenu.add(menuItem7);
		} else if (select.isRoot()) {
			popupMenu.add(menuItem6);
			menuItem6.setText("그룹추가");
		} else {
			popupMenu.add(menuItem1);
			menuItem1.setText("전체쪽지");
			popupMenu.add(menuItem2);
			menuItem2.setText("전체채팅");
			popupMenu.add(menuItem3);
			menuItem3.setText("전체파일전송");
			popupMenu.add(getSeparator());
			popupMenu.add(menuItem6);
			popupMenu.add(menuItem5);
			popupMenu.add(menuItem7);
			menuItem7.setText("그룹삭제");
		}

		menuItem1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent event) {
				noteWrite();
			}
		});
		menuItem2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent event) {
				chat_set();
			}
		});
		menuItem3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent event) {
				fileTrans();
			}
		});
		menuItem4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent event) {
				mailWrite();
			}
		});
		menuItem5.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent event) {
				modifyEmployee();
			}
		});
		menuItem6.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent event) {
				addEmployee();
			
			}
		});
		menuItem7.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent event) {
				deleteEmployee();
			}
		});
		popupMenu.show(tree, x, y);
	}

	protected void noteWrite() {
	      note_f = new Note();
	      selectedNode = getSelectedNode();      
	       CustomTreeNode temp;
	      if (selectedNode.isLeaf()) {
	         System.out.println("쪽지 : " + selectedNode.getEvo().getM_id());
	         note_f.lb_name_to.setText(selectedNode.getEvo().getEmployee_name()); // 이름 셋팅 
	         v_selected.add(selectedNode.getEvo().getM_id());               // 아이디 셋팅 
	         note_f.setV_notter(v_selected, this);
	         note_f.setVisible(true);
	         v_selected.clear();
	      } else {
	         note_f.lb_name_to.setText((String) " ["+selectedNode.getUserObject()+ "] 총 " + selectedNode.getLeafCount() + "명");
	         if (selectedNode.getDepth() == 1) {
	                  for (int i = 0; i < selectedNode.getChildCount(); i++) {
	                     temp = (CustomTreeNode) selectedNode.getChildAt(i);
	                     v_selected.add(temp.getEvo().getM_id());
	                  }
	               } else if (selectedNode.getDepth() == 2) {
	                  for (int i = 0; i < selectedNode.getChildCount(); i++) {
	                     for (int j = 0; j < selectedNode.getChildAt(i)
	                           .getChildCount(); j++) {
	                        temp = (CustomTreeNode) selectedNode.getChildAt(i).getChildAt(j);
	                        v_selected.add(temp.getEvo().getM_id());
	                     }
	                  }
	               }
	         System.out.println("쪽지 : 그룹  / " + v_selected  + selectedNode.getLeafCount());
	         note_f.setV_notter(v_selected, this);
	         note_f.setVisible(true);
	         v_selected.clear();
	      }
	   }

	public void chat_set(){		
		StateSetVO ssvo = new StateSetVO();					// 1. 상태 셋팅 
		ssvo.setVo_type(2);									// 상태를 2번(SetMyInfo)로 셋팅
		PortVO portVo = new PortVO();						// 2. 포트 셋팅 
		portVo.setM_id(clientThread.getSmvo().getM_id()); 	// 포트에 내 아이디 셋팅 
//		clientThread.typeChange(null,"");					// 3. 클라이언트쓰레드에 아무것도 셋팅하지 않음. 		
		try {
			
			chatting();										// 4. 채팅창 실행. 
			portVo.setInvitation_user_list(null);   
	         Vector<String> copy = new Vector<String>();
	         for(int i=0; i<v_selected.size(); i++){
	            copy.add(v_selected.get(i));         
	            System.out.println("v_selected 초대명단의 아이디 : " + v_selected.get(i));
	            System.out.println("copy 초대명단의 아이디 : " + copy.get(i));
	         }
	         
	        portVo.setInvitation_user_list(copy);      // 포트에 id 셋팅		// 포트에 id 셋팅
			System.out.println("chat_set에서 v_selected" + v_selected.get(0));
			portVo.setCommand(1);							// 포트를 챗팅으로 셋팅 
			ssvo.setVo(portVo);								// 상태를 포트로 셋팅 
			clientThread.oos.writeObject(ssvo);				// 클라이언트 쓰레드에 상태를 셋팅 
			clientThread.oos.flush();						// 클라이언트 쓰레드 날림 
			for(int i=0; i<v_selected.size(); i++){
				System.out.println("chat_set에서 v_selected 지우기 전 " + v_selected.elementAt(i));				
			}
			v_selected.clear();								// 벡터를 초기화
			v_selected.removeAllElements();
			//System.out.println("chat_set에서 v_selected 지운 후" + v_selected.get(0));
		} catch (IOException e1) {
			e1.printStackTrace();
		}
	}
	
	protected void chatting() {
		// chat_f = new Chatting();
		selectedNode = getSelectedNode();	   
	    CustomTreeNode temp;
		if (selectedNode.isLeaf()) {
			v_selected.add(selectedNode.getEvo().getM_id());						// 아이디 셋팅 
			System.out.println("EmployeesSearch 채팅 : 1명 다시 갱신 / " + v_selected);
			//chat_f.lb_name_to.setText((String) selectedNode.getUserObject());	// 제목에 셋팅 
			//v_selected_chat.add(selectedNode.getEvo().getEmployee_name());			// 이름 셋팅
        	//chat_f.listset(v_selected_chat);
            //chat_f.setV_chatter(v_selected);
           //v_selected.clear();
		} else {
			//chat_f.lb_name_to.setText((String) " ["+selectedNode.getUserObject()+ "] 총 " + selectedNode.getLeafCount() + "명");
			 if (selectedNode.getDepth() == 1) {
	               for (int i = 0; i < selectedNode.getChildCount(); i++) {
	            	   temp = (CustomTreeNode) selectedNode.getChildAt(i);
	            	   v_selected.add(temp.getEvo().getM_id());							// 아이디 셋팅 
	            	   // v_selected_chat.add(temp.getEvo().getEmployee_name());			// 이름 셋팅
	               }
	            } else if (selectedNode.getDepth() == 2) {
	               for (int i = 0; i < selectedNode.getChildCount(); i++) {
	                  for (int j = 0; j < selectedNode.getChildAt(i).getChildCount(); j++) {
	                	  temp = (CustomTreeNode) selectedNode.getChildAt(i).getChildAt(j);
	                	  v_selected.add(temp.getEvo().getM_id());						// 아이디 셋팅
	                	  //v_selected_chat.add(temp.getEvo().getEmployee_name());		// 이름 셋팅
	                  }
	               }
	            }
	            System.out.println("EmployeesSearch 채팅 : 그룹  갱신 / " + v_selected + selectedNode.getLeafCount());
	            //chat_f.listset(v_selected_chat);
	            //chat_f.setV_chatter(v_selected);
	            //v_selected.clear();        
		}
	}

	protected void fileTrans() {
		file_f = new FileTransfer(this);
		System.out.println("파일 트렌스퍼 생성");
		clientThread.setTemp_ft(file_f);
		System.out.println("클라이언트에 파일 트렌스퍼 연결");
		selectedNode = getSelectedNode();
		System.out.println("값 불러오기 시작");
		CustomTreeNode temp;
		
		if (selectedNode.isLeaf()) {		// 한명
			v_selected.add(selectedNode.getEvo().getM_id());	// id 값 셋팅
			System.out.println("EmployeesSearch 채팅 : 1명 다시 갱신 / " + v_selected);
			
			file_f.lb_name_to.setText(selectedNode.getEvo().getM_id());	// 아이디 셋팅 (라벨)
			
			System.out.println("v_selected에 저장된 값: "+v_selected.get(v_selected.size()-1)); // 아이디 출력
			
			file_f.setV_filer(v_selected);
			
			System.out.println("file_f.setV_filer(v_selected)에 저장된 값: "+file_f.getV_filer().get(0));
		//	file_f.setVisible(true);
			//v_selected.clear();
		} else {
			file_f.lb_name_to.setText((String) " ["+selectedNode.getUserObject()+ "] 총 " + selectedNode.getLeafCount() + "명");
			if (selectedNode.getDepth() == 1) {
				for (int i = 0; i < selectedNode.getChildCount(); i++) {
					temp = (CustomTreeNode) selectedNode.getChildAt(i);
	                v_selected.add(temp.getEvo().getM_id());
				}
			} else if (selectedNode.getDepth() == 2) {
				for (int i = 0; i < selectedNode.getChildCount(); i++) {
					for (int j = 0; j < selectedNode.getChildAt(i).getChildCount(); j++) {
						temp = (CustomTreeNode) selectedNode.getChildAt(i).getChildAt(j);
	                	v_selected.add(temp.getEvo().getM_id());
					}
				}
			}
			System.out.println("EmployeesSearch 파일 : 그룹  갱신 / " + v_selected + selectedNode.getLeafCount());
		}
		
		file_f.setV_filer(v_selected);
		file_f.setVisible(true);
		//v_selected.clear();
	}

	protected void mailWrite() {

	}

	protected void modifyEmployee() {
		CustomTreeNode node = getSelectedNode();
		if (node == null) {
			JOptionPane.showMessageDialog(null, "변경할 이름을 선택하세요.", "Error",
					JOptionPane.ERROR_MESSAGE);
			return;
		}
		String name = JOptionPane.showInputDialog(null, "새로운 이름 입력하세요: ");
		if (name != null && !"".equals(name)) {
			System.out.println(node.getUserObject());
			String value = (String) node.getUserObject();
			
			node.setUserObject(name);
			String next_value =  (String) node.getUserObject();
			change(value, next_value);
		}
	}

	public void change(String value, String next_value){
		for(int i = 0; i< dm_root.getChildCount(); i++){ // 그룹의 개수를
			for(int j = 0; j< dm_root.getChildAt(i).getChildCount(); j++){ // 팀의 개수를 
				CustomTreeNode temp = (CustomTreeNode) dm_root.getChildAt(i).getChildAt(j); // 이름
				if(value.equals(temp.getEvo().getGroup())){
					temp.getEvo().setGroup(next_value);
					if(value.equals(temp.getEvo().getTeam())){
						temp.getEvo().setTeam(next_value);
					}
				}
				else if(value.equals(temp.getEvo().getTeam())){
					temp.getEvo().setTeam(next_value);
				}
			}
		}
		SaveMyGroup();
	}
	
	protected void addEmployee() {
		CustomTreeNode parent = getSelectedNode();
		if (parent.isLeaf()) {
			JOptionPane.showMessageDialog(null, "상위 그룹에서 직원을 추가해주세요.", "Error",
					JOptionPane.ERROR_MESSAGE);
			return;
		} 
		else if(parent.getDepth() == 2){	// 그룹에 추가될 때
			team_name = JOptionPane.showInputDialog(null, "그룹내의 팀명을 입력하세요.");
			String add_user_name = JOptionPane.showInputDialog(null, "찾으실 직원 이름을 적어주세요");
			// 직원 추가르 위한 트리 보여줌
			EmployeesSearch es = new EmployeesSearch();
			es.list_type(1, (String) parent.getUserObject(), team_name);
			es.setTxt_search(add_user_name);
			es.addEmployeeFrame(4, Main.this);
			es.btn_search.doClick();
			es.setVisible(true);		
		}
		else if(parent.getDepth() == 1){	// 팀에 추가될 때
			CustomTreeNode parent_top = (CustomTreeNode) parent.getParent();
			System.out.println((String) parent_top.getUserObject());
			String add_user_name = JOptionPane.showInputDialog(null, "찾으실 직원 이름을 적어주세요");
			// 직원 추가르 위한 트리 보여줌
			EmployeesSearch es = new EmployeesSearch();
			
			es.list_type(2,  (String) parent_top.getUserObject(),  (String) parent.getUserObject());
			es.setTxt_search(add_user_name);
			es.addEmployeeFrame(4, Main.this);
			es.btn_search.doClick();
			es.setVisible(true);		
		}
		else{
			group_name = JOptionPane.showInputDialog(null, "생성할 그룹명을 입력하세요.");
			team_name = JOptionPane.showInputDialog(null, "그룹내의 팀명을 입력하세요.");
			String add_user_name = JOptionPane.showInputDialog(null, "찾으실 직원 이름을 적어주세요");
			// 직원 추가르 위한 트리 보여줌
			EmployeesSearch es = new EmployeesSearch();
			es.list_type(3, group_name, team_name);
			es.setTxt_search(add_user_name);
			es.addEmployeeFrame(4, Main.this);
			es.btn_search.doClick();
			es.setVisible(true);		
		}
		
	}
	
	public void list_commit(int type){
		
		EmployeeSearchVO add_list = new EmployeeSearchVO();
		add_list.setEmployee_name(add_user_name.getEmployee_name());
		add_list.setEmployee_position(add_user_name.getEmployee_position());
		add_list.setGroup(add_user_name.getGroup());
		add_list.setTeam(add_user_name.getTeam());
		add_list.setM_id(add_user_name.getM_id());
		add_list.setCp_group(add_user_name.getCp_group());
		add_list.setCp_team(add_user_name.getCp_team());
		if(type == 1){
			selectedNode = getSelectedNode();
			dm_name = new CustomTreeNode(add_list.getEmployee_name(),add_list);
			dm_team = new CustomTreeNode(add_list.getCp_team());
			dm_team.add(dm_name);
			selectedNode.add(dm_team);
		}
		else if(type == 2){
			selectedNode = getSelectedNode();
			dm_name = new CustomTreeNode(add_list.getEmployee_name(),add_list);
			selectedNode.add(dm_name);
		}
		else if(type == 3){
			dm_name = new CustomTreeNode(add_list.getEmployee_name(),add_list);
			dm_team = new CustomTreeNode(add_list.getCp_team());
			dm_group = new CustomTreeNode(add_list.getCp_group());
			dm_team.add(dm_name);
			dm_group.add(dm_team);
			dm_root.add(dm_group);
		}
		else{
			
		}
		this.scrollPane_1.setViewportView(setTree_1(dm_root));
		
		save.add(add_list);
		SaveMyGroup();
	}

	protected void deleteEmployee() {
		CustomTreeNode node = getSelectedNode();
		String delete_name = (String) node.getUserObject();
		System.out.println("삭제 명단");
		show_save_file_info(save);
		if (node.getDepth() == 2) {	// 그룹 삭제시
			int res1 = JOptionPane.showConfirmDialog(null,
					"그룹 삭제 시, 그룹 내 직원들이 모두 삭제됩니다." + "\n 그룹을 삭제하시겠습니까?",
					"그룹 삭제", JOptionPane.YES_NO_OPTION);
			
			for(int i = 0; i< save.size(); i++){
				if(delete_name.equals(save.get(i).getCp_group())){
					showEm(save.get(i));
					save.remove(i);
				}
			}
			
			if (res1 == JOptionPane.OK_OPTION) {
				DefaultTreeModel model = (DefaultTreeModel) (tree.getModel());
				TreePath[] paths = tree.getSelectionPaths();
				for (int i = 0; i < paths.length; i++) {
					node = (CustomTreeNode) (paths[i]
							.getLastPathComponent());
					model.removeNodeFromParent(node);
				}
			}
		}
		else if(node.getDepth() == 1){	// 팀 삭제시
			int res1 = JOptionPane.showConfirmDialog(null,
					"팀 삭제 시, 팀 내 직원들이 모두 삭제됩니다." + "\n 팀을 삭제하시겠습니까?",
					"팀 삭제", JOptionPane.YES_NO_OPTION);
			
			if (res1 == JOptionPane.OK_OPTION) {
				
				for(int i = 0; i< save.size(); i++){
					if(delete_name.equals(save.get(i).getCp_team())){
						showEm(save.get(i));
						save.remove(i);
					}
				}
				
				DefaultTreeModel model = (DefaultTreeModel) (tree.getModel());
				TreePath[] paths = tree.getSelectionPaths();
				for (int i = 0; i < paths.length; i++) {
					node = (CustomTreeNode) (paths[i]
							.getLastPathComponent());
					model.removeNodeFromParent(node);
				}
			}
			
		}
		else {	// 직원 삭제시
			int res = JOptionPane.showConfirmDialog(null, "삭제하시겠습니까?", "삭제", JOptionPane.YES_NO_OPTION);
			if (res == JOptionPane.OK_OPTION) {
				
				for(int i = 0; i< save.size(); i++){
					if(delete_name.equals(save.get(i).getEmployee_name())){
						showEm(save.get(i));
						save.remove(i);
						break;
					}
				}
				
				DefaultTreeModel model = (DefaultTreeModel) (tree.getModel());
				TreePath[] paths = tree.getSelectionPaths();
				for (int i = 0; i < paths.length; i++) {
					node = (CustomTreeNode) (paths[i]
							.getLastPathComponent());
					model.removeNodeFromParent(node);
				}//end for
			}//end if
		}
		SaveMyGroup();
	}

	public void showEm(EmployeeSearchVO v){
		System.out.println("==== 직원 정보 ====");
		System.out.println("이름 : " + v.getEmployee_name());
		System.out.println("직위 : " + v.getEmployee_position());
		System.out.println("기존 그룹 : " + v.getGroup());
		System.out.println("기존 팀 : " + v.getTeam());
		System.out.println("변경된 그룹 : " + v.getCp_group());
		System.out.println("변경된 팀 : " + v.getCp_team());
		System.out.println("아이디 : " + v.getM_id());
		System.out.println("==== ====== ====");
	}
	private void expandTree(JTree tree) { // 검색했을 때 펼쳐져서 나옴
		CustomTreeNode dm_root = (CustomTreeNode) tree
				.getModel().getRoot();
		Enumeration e = dm_root.breadthFirstEnumeration();
		while (e.hasMoreElements()) {
			CustomTreeNode node = (CustomTreeNode) e
					.nextElement();
			if (node.isLeaf())
				continue;
			int row = tree.getRowForPath(new TreePath(node.getPath()));
			tree.expandRow(row);
		}
	}

	private CustomTreeNode getSelectedNode() { // getSelctedNode
		return (CustomTreeNode) tree.getLastSelectedPathComponent();
	}
	
	public void show_exception_message(){
		JOptionPane.showMessageDialog(this, "다른 pc에서 로그인 되었습니다.");
		JOptionPane.showMessageDialog(this, "메신저를 종료합니다.");
		System.exit(1);
	}
	// 정보 셋팅 
	public void setLbl_name(String e_name){
		this.e_name = e_name;
		lbl_name.setText(" " +e_name);
	}
	public void setLbl_position(String e_position){
		lbl_position.setText(" [" + e_position+ "] ");
	}
	
	public void setLbl_team(String d_code){
		lbl_team.setText(d_code+ " ");
	}
	
	static private class ToolTipTreeCellRenderer extends DefaultTreeCellRenderer {
	      TreePath oldSelectedPath = null;

	    public ToolTipTreeCellRenderer() {
		}
	      
	      private ToolTipTreeCellRenderer(JTree tree) {
	         tree.addMouseMotionListener(new MouseMotionListener() {
	            public void mouseDragged(MouseEvent mouseEvent) {
	               // Nothing to do
	            }
	            public void mouseMoved(MouseEvent mouseEvent) {
	               DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel();
	               int selRow = tree.getRowForLocation(mouseEvent.getX(), mouseEvent.getY());
	               if (selRow < 0) {	                  
	                  TreePath currentSelected = oldSelectedPath;
	                  oldSelectedPath = null;
	                  if (currentSelected != null)
	                     treeModel.nodeChanged((TreeNode) currentSelected.getLastPathComponent());
	                  
	               } 
	               else {	                  
	                  tree.setSelectionRow(selRow);
	                  TreePath selectedPath = tree.getPathForLocation(mouseEvent.getX(), mouseEvent.getY());
	                  if ((oldSelectedPath == null) || !selectedPath.equals(oldSelectedPath)) {
	                     oldSelectedPath = selectedPath;
	                     treeModel.nodeChanged((TreeNode) oldSelectedPath.getLastPathComponent());
	                  }
	               }
	               tree.repaint();
	            }
	         });
	      }
	      @Override
	        public Component getTreeCellRendererComponent( JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
	        {
	            JComponent comp = (JComponent) super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
	            comp.setOpaque(true);
	            boolean highlight = (oldSelectedPath != null) && (value == oldSelectedPath.getLastPathComponent());
	            comp.setBackground(highlight ? new Color(173, 216, 230) : tree.getBackground());
	            return comp;
	        }
	      
	     
	}

	public ClientThread getClientThread() {
		return clientThread;
	}

	public void setClientThread(ClientThread clientThread) {
		this.clientThread = clientThread;
	}	
	private JPanel getPanel_icon_menu() {
		if (panel_icon_menu == null) {
			panel_icon_menu = new JPanel();
			panel_icon_menu.setBackground(new Color(152,191,218));
			panel_icon_menu.setOpaque(false);
			panel_icon_menu.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
			panel_icon_menu.add(getBtn_minimize());
			panel_icon_menu.add(getBtn_maximize());
			panel_icon_menu.add(getBtn_close());
		}
		return panel_icon_menu;
	}
	private JButton getBtn_minimize() {
		if (btn_minimize == null) {
			btn_minimize = new JButton("");
			btn_minimize.setBackground(new Color(152,191,218));
			btn_minimize.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					setState(JFrame.ICONIFIED);	
				}
			});
			btn_minimize.setIcon(new ImageIcon("C:\\Program Files\\Mino Corp\\system\\minimum.png"));
			btn_minimize.setBorder(null);
		}
		return btn_minimize;
	}
	private JButton getBtn_maximize() {
		if (btn_maximize == null) {
			btn_maximize = new JButton("");
			btn_maximize.setBackground(new Color(152,191,218));
			btn_maximize.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					if(maximum !=true){
						setExtendedState(JFrame.MAXIMIZED_BOTH);	
						btn_maximize.setIcon(new ImageIcon("C:\\Program Files\\Mino Corp\\system\\initsize.png"));
						maximum = true;
					}else{
						setBounds(width-300, 0, 300, 500);
						btn_maximize.setIcon(new ImageIcon("C:\\Program Files\\Mino Corp\\system\\maximum.png"));
						maximum = false;
					}
				}
			});
			btn_maximize.setIcon(new ImageIcon("C:\\Program Files\\Mino Corp\\system\\maximum.png"));
			btn_maximize.setBorder(null);
		}
		return btn_maximize;
	}
	private JButton getBtn_close() {
		if (btn_close == null) {
			btn_close = new JButton("");
			btn_close.setBackground(new Color(152,191,218));
			btn_close.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					systemIcon();
				    setExtendedState(JFrame.ICONIFIED); 
				}
			});
			btn_close.setIcon(new ImageIcon("C:\\Program Files\\Mino Corp\\system\\close.png"));
			btn_close.setBorder(null);
		}
		return btn_close;
	}
	private JPanel getPanel_myinfo_name() {
		if (panel_myinfo_name == null) {
			panel_myinfo_name = new JPanel();
			panel_myinfo_name.setBorder(new EmptyBorder(0, 5, 0, 0));
			panel_myinfo_name.setOpaque(false);
			panel_myinfo_name.setLayout(new BorderLayout(0, 0));
			panel_myinfo_name.add(getLblNewLabel(), BorderLayout.NORTH);
		}
		return panel_myinfo_name;
	}
	private JPanel getPanel_17() {
		if (panel_south == null) {
			panel_south = new JPanel();
			panel_south.setBackground(new Color(152,191,218));
			panel_south.setBorder(new EmptyBorder(0, 0, 5, 0));
			panel_south.setLayout(new BorderLayout(0, 0));
			panel_south.add(getTxt_notice(), BorderLayout.NORTH);
			panel_south.add(getTxt_team(), BorderLayout.SOUTH);
		}
		return panel_south;
	}
	private JTextField getTxt_notice() {
		if (txt_notice == null) {
			txt_notice = new JTextField();
			txt_notice.setText("공지사항 출력");
			txt_notice.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
			txt_notice.setColumns(10);
		}
		return txt_notice;
	}
	private JTextField getTxt_team() {
		if (txt_team == null) {
			txt_team = new JTextField();
			txt_team.setVisible(false);
			txt_team.setText("팀 공지사항 출력");
			txt_team.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
			txt_team.setColumns(10);
		}
		return txt_team;
	}
	private JMenuItem getMenuItem_myinfo() {
		if (menuItem_myinfo == null) {
			menuItem_myinfo = new JMenuItem("내 정보 변경");
			menuItem_myinfo.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
			menuItem_myinfo.setBackground(Color.WHITE);
		}
		return menuItem_myinfo;
	}
	private JSeparator getSeparator_2_1() {
		if (separator_2 == null) {
			separator_2 = new JSeparator();
			separator_2.setBackground(Color.WHITE);
		}
		return separator_2;
	}
	private JPanel getPanel() {
		if (panel == null) {
			panel = new JPanel();
			panel.setBackground(new Color(102, 255, 0));
			panel.setOpaque(false);
			panel.setLayout(new BorderLayout(0, 0));
			panel.add(getComboBox(), BorderLayout.SOUTH);
		}
		return panel;
	}
	private JPanel getPanel_2() {
		if (panel_2 == null) {
			panel_2 = new JPanel();
			panel_2.setBorder(null);
			panel_2.setForeground(Color.WHITE);
			panel_2.setFont(new Font("맑은 고딕", Font.BOLD, 12));
			panel_2.setOpaque(false);
			panel_2.setLayout(new GridLayout(0, 3, 0, 0));
			panel_2.add(getBtnNewButton_4());
			panel_2.add(getBtnNewButton_3());
			panel_2.add(getBtnNewButton_1());
		}
		return panel_2;
	}
	private JButton getButton() {
		if (button == null) {
			button = new JButton("출근체크");
			button.setForeground(Color.WHITE);
			button.setFont(new Font("맑은 고딕", Font.BOLD, 11));
			button.setBorder(null);
			button.setBackground(new Color(197,197,197));
		}
		return button;
	}
	private JPanel getPanel_1() {
		if (panel_1 == null) {
			panel_1 = new JPanel();
			panel_1.setBackground(new Color(152,191,218));
			panel_1.setLayout(new BorderLayout(0, 0));
			panel_1.add(getPanel_3(), BorderLayout.SOUTH);
		}
		return panel_1;
	}
	private JPanel getPanel_3() {
		if (panel_3 == null) {
			panel_3 = new JPanel();
			panel_3.setBackground(new Color(152,191,218));
			panel_3.add(getLbl_name());
			panel_3.add(getLbl_position());
			panel_3.add(getLbl_team());
		}
		return panel_3;
	}
	private JLayeredPane getLayeredPane_1() {
		if (layeredPane == null) {
			layeredPane = new JLayeredPane();
			layeredPane.setOpaque(true);
			layeredPane.add(getLblNewLabel_2());
		}
		return layeredPane;
	}
	private JLabel getLblNewLabel_2() {
		if (lblNewLabel_2 == null) {
			lblNewLabel_2 = new JLabel("");
			lblNewLabel_2.setIcon(new ImageIcon("C:\\Users\\user\\Desktop\\title_bar.png"));
			lblNewLabel_2.setBounds(0, 0, 296, 103);
		}
		return lblNewLabel_2;
	}
	private JLabel getLblNewLabel() {
		if (lblNewLabel == null) {
			lblNewLabel = new JLabel("");
			lblNewLabel.setIcon(new ImageIcon("C:\\Program Files\\Mino Corp\\profile\\myprofile.png"));
		}
		return lblNewLabel;
	}
}
